package org.karelun.rabbit.rcp.editpart;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.draw2d.PolylineDecoration;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.karelun.ideaboard.gef.EditPolicy;
import org.karelun.ideaboard.gef.editparts.AbstractConnectionEditPart;
import org.karelun.ideaboard.gef.editpolicies.ConnectionEndpointEditPolicy;
import org.karelun.rabbit.rcp.policy.DeleteConnectionEditPolicy;

public class ConnectionLineEditPart extends AbstractConnectionEditPart{

	private EditingDomain editingDomain;
	
	public ConnectionLineEditPart(EditingDomain editingDomain){
		this.editingDomain=editingDomain;
	}
	
	@Override
	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.CONNECTION_ROLE, new DeleteConnectionEditPolicy());
		installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE, new ConnectionEndpointEditPolicy());
	}
	
	@Override
	protected IFigure createFigure() {
		PolylineConnection line = (PolylineConnection)super.createFigure();
		line.setTargetDecoration(new PolylineDecoration());
		return line;
	}

	@Override
	public Object getAdapter(Class key) {
		if(key==EditingDomain.class){
			return editingDomain;
		}
		return super.getAdapter(key);
	}
}
